package c.a.a.d0;

import android.graphics.Color;
import android.graphics.PointF;
import c.a.a.b0.k.c;
import c.a.a.d0.h0.c.b;
import c.a.a.e0.f;
import com.pgl.sys.ces.out.ISdkLite;
import java.io.IOException;
import java.util.ArrayList;

/* compiled from: GradientColorParser */
public class k implements g0<c> {
    public int a;

    public k(int i) {
        this.a = i;
    }

    public Object a(c.a.a.d0.h0.c cVar, float f) throws IOException {
        int i;
        ArrayList arrayList = new ArrayList();
        int i2 = 0;
        Object obj = cVar.u0() == b.BEGIN_ARRAY ? 1 : null;
        if (obj != null) {
            cVar.n();
        }
        while (cVar.t()) {
            arrayList.add(Float.valueOf((float) cVar.w()));
        }
        if (obj != null) {
            cVar.q();
        }
        if (this.a == -1) {
            this.a = arrayList.size() / 4;
        }
        int i3 = this.a;
        float[] fArr = new float[i3];
        int[] iArr = new int[i3];
        int i4 = 0;
        int i5 = 0;
        int i6 = 0;
        while (true) {
            i = this.a * 4;
            if (i4 >= i) {
                break;
            }
            i = i4 / 4;
            double floatValue = (double) ((Float) arrayList.get(i4)).floatValue();
            int i7 = i4 % 4;
            if (i7 == 0) {
                fArr[i] = (float) floatValue;
            } else if (i7 == 1) {
                i5 = (int) (floatValue * 255.0d);
            } else if (i7 == 2) {
                i6 = (int) (floatValue * 255.0d);
            } else if (i7 == 3) {
                iArr[i] = Color.argb(ISdkLite.REGION_UNSET, i5, i6, (int) (floatValue * 255.0d));
            }
            i4++;
        }
        c cVar2 = new c(fArr, iArr);
        if (arrayList.size() > i) {
            i3 = (arrayList.size() - i) / 2;
            double[] dArr = new double[i3];
            double[] dArr2 = new double[i3];
            i6 = 0;
            while (i < arrayList.size()) {
                if (i % 2 == 0) {
                    dArr[i6] = (double) ((Float) arrayList.get(i)).floatValue();
                } else {
                    dArr2[i6] = (double) ((Float) arrayList.get(i)).floatValue();
                    i6++;
                }
                i++;
            }
            while (true) {
                int[] iArr2 = cVar2.b;
                if (i2 >= iArr2.length) {
                    break;
                }
                c cVar3;
                double d;
                int i8 = iArr2[i2];
                double d2 = (double) cVar2.a[i2];
                for (int i9 = 1; i9 < i3; i9++) {
                    int i10 = i9 - 1;
                    double d3 = dArr[i10];
                    double d4 = dArr[i9];
                    if (dArr[i9] >= d2) {
                        d2 = (d2 - d3) / (d4 - d3);
                        cVar3 = cVar2;
                        PointF pointF = f.a;
                        double max = Math.max(0.0d, Math.min(1.0d, d2));
                        d2 = dArr2[i10];
                        d = ((dArr2[i9] - d2) * max) + d2;
                        break;
                    }
                    cVar3 = cVar2;
                }
                cVar3 = cVar2;
                d = dArr2[i3 - 1];
                c cVar4 = cVar3;
                cVar4.b[i2] = Color.argb((int) (d * 255.0d), Color.red(i8), Color.green(i8), Color.blue(i8));
                i2++;
                cVar2 = cVar4;
            }
        }
        return cVar2;
    }
}
